﻿/*-----------------------------------------------
// File: BattleData.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ProtoBuf.Message;

public class BattleData
{
    public string fightId;
    public BattleType battleType;
    public string mapSceneName;
    public bool attackFirst;
    public long randomSeed;
    public string targetFrag;
    public int maxRound;
    public string chapterId;
    public ProtoBuf.Message.BattlePlayer myCopyBattlePlayer = null;


    public List<BattleFighterData> attackFighters = new List<BattleFighterData>();
    public List<BattleFighterData> defendFighters = new List<BattleFighterData>();
    public double attackerFactor = 1;
    public double defenderFactor = 1;

    #region Rush 胜利特殊条件
    public int rushWinKey;
    public int rushWinValue;
    #endregion

    public bool isPlayBack = false;
    public ProtoBuf.Message.BattleOperate operateRecord = null;

    public const int DEFAULT_MAX_ROUND = 40;

    public void SetPlaybackData(ProtoBuf.Message.SCFightPlayback msg)
    {
        Clear();
        isPlayBack = true;
        operateRecord = msg.optRecord;
        fightId = msg.fightid;
        battleType = (BattleType)msg.battleType;
        mapSceneName = "map_arena_001";
        randomSeed = msg.randSeed;
        attackerFactor = msg.attackerFactor;
        defenderFactor = msg.defenderFactor;

        var attacker = new BattleFighterData(msg.attacker, 0, true, 0, attackerFactor);
        attackFighters.Add(attacker);
        if (battleType == BattleType.PVE || battleType == BattleType.ACTIVITY || battleType == BattleType.FIELD_PVE ||
            battleType == BattleType.RUSH || battleType == BattleType.RUSH_BOSS || battleType == BattleType.FIELD_BOSS ||
            battleType == BattleType.WANTED)
        {
            var defender = new BattleFighterData(msg.defender2, 1, true, 0, defenderFactor);
            defendFighters.Add(defender);
            attackFirst = true;
        }
        else if (battleType == BattleType.PVP || battleType == BattleType.PLUNDER || battleType == BattleType.FIELD_PVP)
        {
            var defender = new BattleFighterData(msg.defender1, 1, true, 0, defenderFactor);
            defendFighters.Add(defender);
            if (msg.attacker.inst.firstOrder == 0 && msg.defender1.inst.firstOrder == 1)
            {
                attackFirst = false;
            }
            else if (msg.attacker.inst.firstOrder == 1 && msg.defender1.inst.firstOrder == 0)
            {
                attackFirst = true;
            }
            else
            {
                Debug.LogError("[PlayBack Error] order error. attacker:" + msg.attacker.inst.firstOrder + " defender:" + msg.defender1.inst.firstOrder);
                attackFirst = true;
            }
        }

        maxRound = msg.maxRound > 0 ? msg.maxRound : DEFAULT_MAX_ROUND;
    }

    public void SetRecruitShowData(int space)
    {
        Clear();
        fightId = "";
        battleType = BattleType.RECRUIT_SHOW;
        mapSceneName = "map_arena_001";
        attackFirst = true;
        randomSeed = 0;
        attackFighters = new List<BattleFighterData>();
        var attacker = new BattleFighterData();
        attacker.isAuto = false;
        attacker.waveNum = 0;
        attacker.isPlayer = true;
        attacker.camp = 0;
        attacker.role = new BattlePlayerActorData();
        attacker.actors = new List<BattleActorData>();
        attacker.damageFactor = 1f;
        long uid = 10000L;
        foreach (var dict in Dict.Blo.DictHeroBlo.GetTableRecruitShowHero(space, 0))
        {
            var hero = new BattleActorData(uid.ToString(), dict);
            attacker.actors.Add(hero);
            uid++;
        }
        attackFighters.Add(attacker);
        defendFighters = new List<BattleFighterData>();
        var defender = new BattleFighterData();
        defender.isAuto = true;
        defender.waveNum = 0;
        defender.isPlayer = false;
        defender.camp = 1;
        defender.role = new BattlePlayerActorData();
        defender.actors = new List<BattleActorData>();
        defender.damageFactor = 1f;
        foreach (var dict in Dict.Blo.DictHeroBlo.GetTableRecruitShowHero(space, 1))
        {
            var hero = new BattleActorData(uid.ToString(), dict);
            defender.actors.Add(hero);
            uid++;
        }
        defendFighters.Add(defender);

        maxRound = 20;

    }


    public void SetBootFightData()
    {
        Clear();
        fightId = "";
        battleType = BattleType.FIRST;
        mapSceneName = "map_startscenes_001";
        attackFirst = true;
        randomSeed = 0;
        attackFighters = new List<BattleFighterData>();
        var attacker = new BattleFighterData();
        attacker.isAuto = false;
        attacker.waveNum = 0;
        attacker.isPlayer = true;
        attacker.camp = 0;
        attacker.role = new BattlePlayerActorData();
        attacker.actors = new List<BattleActorData>();
        attacker.damageFactor = 1f;
        long uid = 10000L;
        foreach (var dict in Dict.Blo.DictHeroBlo.GetTableBootHeroByCamp(attacker.camp))
        {
            var hero = new BattleActorData(uid.ToString(), dict);
            attacker.actors.Add(hero);
            uid++;

            if (dict.HeroId == "hero_001")
            {
                hero.weaponId = "equip_005";
            }
        }
        attackFighters.Add(attacker);
        defendFighters = new List<BattleFighterData>();
        var defender = new BattleFighterData();
        defender.isAuto = true;
        defender.waveNum = 0;
        defender.isPlayer = false;
        defender.camp = 1;
        defender.role = new BattlePlayerActorData();
        defender.actors = new List<BattleActorData>();
        defender.damageFactor = 1f;
        foreach (var dict in Dict.Blo.DictHeroBlo.GetTableBootHeroByCamp(defender.camp))
        {
            var hero = new BattleActorData(uid.ToString(), dict);
            defender.actors.Add(hero);
            uid++;
        }
        defendFighters.Add(defender);
        maxRound = 20;
    }


    public void SetData(ProtoBuf.Message.SCFightTreasureStartResult msg, string targetFrag)
    {
        Clear();
        this.targetFrag = targetFrag;
        fightId = msg.fightId;
        battleType = BattleType.PLUNDER;
        mapSceneName = "map_arena_001";
        randomSeed = msg.randSeed;
        var attackFighter = new BattleFighterData(msg.playerList[0], 0, true, 0, attackerFactor);
        attackFighters.Add(attackFighter);

        var defendFighter = new BattleFighterData(msg.playerList[1], 1, true, 0, defenderFactor);
        defendFighters.Add(defendFighter);
        if (msg.playerList[0].inst.firstOrder == 1 && msg.playerList[1].inst.firstOrder == 0)
        {
            attackFirst = true;
        }
        else if (msg.playerList[0].inst.firstOrder == 0 && msg.playerList[1].inst.firstOrder == 1)
        {
            attackFirst = false;
        }
        else
        {
            Debug.LogError("[PVP Fight Error] order error. attacker:" + msg.playerList[0].inst.firstOrder + " defender:" + msg.playerList[1].inst.firstOrder);
            attackFirst = true;
        }


        maxRound = 20;
    }

    public void SetTestData1(List<string> attack, List<string> defend)
    {
        Clear();
        fightId = "";
        battleType = BattleType.PVE;
        mapSceneName = "map_arena_001";
        attackFirst = true;
        randomSeed = 0;
        attackerFactor = 1f;
        defenderFactor = 1f;
        
        var attackFighter = new BattleFighterData(Battle.Engine.Test.GetTestBattlePlayer(attack, 10000L), 0, false, 0, attackerFactor);
        attackFighters.Add(attackFighter);
        attackFighter.angerNum = 300;
        foreach (var f in attackFighter.actors)
        {
            f.hp = 10000;
            f.att = 100;
            f.dodge = 0f;
        }

        var defendFighter = new BattleFighterData(Battle.Engine.Test.GetTestBattlePlayer(defend, 20000L), 1, true, 0, defenderFactor);
        defendFighters.Add(defendFighter);
        foreach (var f in defendFighter.actors)
        {
            f.hp = 10000;
            f.att = 1;
            f.dodge = 0f;
        }

        maxRound = 20;
    }
    public void SetTestData(BattleType t, int taskId)
    {
        Clear();
        fightId = "";
        battleType = t;
        mapSceneName = "map_forest_002";
        attackFirst = true;
        randomSeed = 0;
        var attackFighter = new BattleFighterData(Battle.Engine.Test.GetTestBattlePlayer(), 0, StaticData.isPveAutoCache, 0, attackerFactor);
        attackFighters.Add(attackFighter);
        attackFighter.angerNum = 300;

        var defendFighter = new BattleFighterData(Battle.Engine.Test.GetTestBattleMonster(taskId, 0), 1, true, 0, defenderFactor);
        defendFighters.Add(defendFighter);

        maxRound = 20;
    }

    public void SetData(SCRebelFightStart msg)
    {
        Clear();
        fightId = msg.fightId;
        battleType = BattleType.WANTED;
        if (string.IsNullOrEmpty(msg.fightRoomId))
        {
            mapSceneName = "map_arena_001";
        }
        else
        {
            mapSceneName = msg.fightRoomId;
        }
        attackerFactor = msg.damageFactor;
        attackFirst = true;
        randomSeed = msg.randSeed;
        var attackFighter = new BattleFighterData(msg.battlePlayer, 0, StaticData.isPveAutoCache, 0,attackerFactor);
        attackFighters.Add(attackFighter);
        int monsterWave = 0;
        foreach (var monster in msg.battleMonsterList)
        {
            var defendFighter = new BattleFighterData(monster, 1, true, monsterWave, defenderFactor);
            defendFighters.Add(defendFighter);
            monsterWave++;
        }
        maxRound = 20;

    }

    public void SetData(SCUFFightRecordReplay msg)
    {
        Clear();
        fightId = msg.fightId;
        randomSeed = msg.randomSeed;
        mapSceneName = string.IsNullOrEmpty(msg.roomId) ? "map_forest_002" : msg.roomId;
        maxRound = msg.maxRound > 0 ? msg.maxRound : DEFAULT_MAX_ROUND;
        battleType = BattleType.FRIEND_PVP;
        long winId = msg.winPlayerId;
        attackerFactor = msg.attackerDamageFactor;
        defenderFactor = msg.defenderDamageFactor;
        var attackFighter = new BattleFighterData(msg.playerList[0], 0, true, 0, attackerFactor);
        attackFighters.Add(attackFighter);

        var defendFighter = new BattleFighterData(msg.playerList[1], 1, true, 0, defenderFactor);
        defendFighters.Add(defendFighter);
    }

    public void SetData(SCCopyFightStart msg)
    {
        Clear();
        fightId = msg.fightId;
        battleType = BattleType.PVE;
        if (string.IsNullOrEmpty(msg.fightScene))
        {
            mapSceneName = "map_forest_002";
        }
        else
        {
            mapSceneName = msg.fightScene;
        }
        attackFirst = true;
        randomSeed = msg.randSeed;
        var attackFighter = new BattleFighterData(msg.battlePlayer, 0, StaticData.isPveAutoCache, 0, attackerFactor);
        attackFighters.Add(attackFighter);

        int monsterWave = 0;
        foreach (var monster in msg.battleMonsterList)
        {
            var defendFighter = new BattleFighterData(monster, 1, true, monsterWave, defenderFactor);
            defendFighters.Add(defendFighter);
            monsterWave++;
        }

        maxRound = msg.maxRound > 0 ? msg.maxRound : DEFAULT_MAX_ROUND;

        myCopyBattlePlayer = msg.battlePlayer;
    }

    public void SetData(ProtoBuf.Message.SCPvpFightResult msg)
    {
        Clear();
        fightId = msg.fightId;
        battleType = BattleType.PVP;
        if (!string.IsNullOrEmpty(msg.roomId))
        {
            mapSceneName = msg.roomId;
        }
        else
        {
            mapSceneName = "map_arena_001";
        }
        randomSeed = msg.randSeed;

        var attackFighter = new BattleFighterData(msg.playerList[0], 0, true, 0, attackerFactor);
        attackFighters.Add(attackFighter);

        var defendFighter = new BattleFighterData(msg.playerList[1], 1, true, 0, defenderFactor);
        defendFighters.Add(defendFighter);

        if (msg.playerList[0].inst.firstOrder == 1 && msg.playerList[1].inst.firstOrder == 0)
        {
            attackFirst = true;
        }
        else if (msg.playerList[0].inst.firstOrder == 0 && msg.playerList[1].inst.firstOrder == 1)
        {
            attackFirst = false;
        }
        else
        {
            Debug.LogError("[PVP Fight Error] order error. attacker:" + msg.playerList[0].inst.firstOrder + " defender:" + msg.playerList[1].inst.firstOrder);
            attackFirst = true;
        }

        maxRound = msg.maxRoundNum > 0 ? msg.maxRoundNum : DEFAULT_MAX_ROUND;
    }


    public void SetData(ProtoBuf.Message.SidePvpFightData msg)
    {
        Clear();
        fightId = "";
        mapSceneName = Dict.Blo.DictFieldBlo.GetOne(StaticData.fieldId).BattleMap;

        randomSeed = msg.randSeed;
        battleType = BattleType.FIELD_PVP;

        if (msg.attPlayer.inst.firstOrder == 1 && msg.defPlayer.inst.firstOrder == 0)
        {
            attackFirst = true;
        }
        else if (msg.attPlayer.inst.firstOrder == 0 && msg.defPlayer.inst.firstOrder == 1)
        {
            attackFirst = false;
        }
        else
        {
            Debug.LogError("[PVP Fight Error] order error. attacker:" + msg.attPlayer.inst.firstOrder + " defender:" + msg.defPlayer.inst.firstOrder);
            attackFirst = true;
        }
        var attackFighter = new BattleFighterData(msg.attPlayer, 0, true, 0, attackerFactor);
        attackFighters.Add(attackFighter);

        var defendFighter = new BattleFighterData(msg.defPlayer, 1, true, 0, defenderFactor);
        defendFighters.Add(defendFighter);

        maxRound = msg.maxRoundCount > 0 ? msg.maxRoundCount : DEFAULT_MAX_ROUND;
    }

    public void SetData(SCSidePveFightStart msg)
    {
        Clear();
        fightId = msg.fightId;
        attackFirst = true;
        randomSeed = msg.randSeed;
        mapSceneName = string.IsNullOrEmpty(msg.fightScene)? Dict.Blo.DictFieldBlo.GetOne(StaticData.fieldId).BattleMap: "map_arena_001";
        battleType = BattleType.FIELD_PVE;
        
        var attackFighter = new BattleFighterData(msg.battlePlayer, 0, false, 0, attackerFactor);
        attackFighters.Add(attackFighter);

        var defendFighter = new BattleFighterData(msg.battleMonsterList[0], 1, true, 0, defenderFactor);
        defendFighters.Add(defendFighter);

        myCopyBattlePlayer = msg.battlePlayer;

        maxRound = msg.maxround > 0 ? msg.maxround : DEFAULT_MAX_ROUND;
    }

    public void SetData(SCSidePveBossFightStart msg)
    {
        Clear();
        fightId = msg.fightId;
        attackFirst = true;
        randomSeed = msg.randSeed;
        mapSceneName = string.IsNullOrEmpty(msg.fightScene) ? Dict.Blo.DictFieldBlo.GetOne(StaticData.fieldId).BattleMap : "map_arena_001";
        battleType = BattleType.FIELD_BOSS;

        var attackFighter = new BattleFighterData(msg.battlePlayer, 0, false, 0, attackerFactor);
        attackFighters.Add(attackFighter);

        var defendFighter = new BattleFighterData(msg.battleMonsterList[0], 1, true, 0, defenderFactor);
        defendFighters.Add(defendFighter);

        myCopyBattlePlayer = msg.battlePlayer;

        maxRound = msg.maxround > 0 ? msg.maxround : DEFAULT_MAX_ROUND;
    }

    public void SetData(SCFriendFight msg)
    {
        Clear();
        fightId = msg.fightId;

        if (msg.playerList[0].inst.firstOrder == 1 && msg.playerList[1].inst.firstOrder == 0)
            attackFirst = true;
        else if (msg.playerList[0].inst.firstOrder == 0 && msg.playerList[1].inst.firstOrder == 1)
            attackFirst = false;
        else
        {
            Debug.LogError("[Friend Fight Error] order error. attacker:" + msg.playerList[0].inst.firstOrder + " defender:" + msg.playerList[1].inst.firstOrder);
            attackFirst = true;
        }

        randomSeed = msg.randSeed;
        mapSceneName = string.IsNullOrEmpty(msg.roomId)? mapSceneName = "map_forest_001": msg.roomId;
        battleType = BattleType.FRIEND_PVP;

        var attackFighter = new BattleFighterData(msg.playerList[0], 0, true, 0, attackerFactor);
        attackFighters.Add(attackFighter);

        var defendFighter = new BattleFighterData(msg.playerList[1], 1, true, 0, defenderFactor);
        defendFighters.Add(defendFighter);

        maxRound = msg.maxRoundNum > 0 ? msg.maxRoundNum : DEFAULT_MAX_ROUND;
    }

    public void SetData(ProtoBuf.Message.SCDailyCopyFightStart msg)
    {
        Clear();
        fightId = msg.fightId;
        attackFirst = true;
        if (!string.IsNullOrEmpty(msg.roomId))
            mapSceneName = msg.roomId;
        else
            mapSceneName = "map_forest_002";
        randomSeed = msg.randSeed;
        battleType = BattleType.ACTIVITY;
        maxRound = msg.maxRoundNum > 0 ? msg.maxRoundNum : DEFAULT_MAX_ROUND;
        var attackFighter = new BattleFighterData(msg.battlePlayer, 0, false, 0, attackerFactor);
        attackFighters.Add(attackFighter);

        var defendFighter = new BattleFighterData(msg.monster, 1, true, 0, defenderFactor);
        defendFighters.Add(defendFighter);

    }

    public void SetData(ProtoBuf.Message.SCPvpFightResultGuide msg)
    {
        Clear();
        fightId = msg.fightId;
        battleType = BattleType.PVP;
        if (!string.IsNullOrEmpty(msg.roomId))
            mapSceneName = msg.roomId;
        else
            mapSceneName = "map_arena_001";
        // TEMP
        attackFirst = true;
        randomSeed = msg.randSeed;

        var attackFighter = new BattleFighterData(msg.playerList[0], 0, true, 0, attackerFactor);
        attackFighters.Add(attackFighter);

        var defendFighter = new BattleFighterData(msg.playerList[1], 1, true, 0, defenderFactor);
        defendFighters.Add(defendFighter);

        maxRound = msg.maxRoundNum > 0 ? msg.maxRoundNum : DEFAULT_MAX_ROUND;
    }
    /*
    public void SetData(ProtoBuf.Message.SCSidePvpFightResult msg)
    {
        Clear();
        fightId = msg.fightId;
        battleType = BattleType.FIELD_PVP;
        mapSceneName = string.IsNullOrEmpty(msg.roomId) ? "map_forest_002" : msg.roomId;
        // TEMP
        attackFirst = true;
        randomSeed = msg.randSeed;


        var attackFighter = new BattleFighterData(msg.attacker, 0, true, 0);
        attackFighters.Add(attackFighter);

        var defendFighter = new BattleFighterData(msg.defender, 1, true, 0);
        defendFighters.Add(defendFighter);

        maxRound = msg.maxRoundNum>0?msg.maxRoundNum:20;
    }*/

    public void SetData(ProtoBuf.Message.SCRushFightStart msg, bool isRush)
    {
        Clear();
        fightId = msg.fightId;
        Debug.Log("fightid: " + fightId);
        if (isRush)
        {
            battleType = BattleType.RUSH;
        }
        else
        {
            battleType = BattleType.RUSH_BOSS;
        }

        randomSeed = msg.randSeed;
        mapSceneName = string.IsNullOrEmpty(msg.fightScene) ? "map_maze_001" : msg.fightScene;
        attackFirst = true;
        var attackFighter = new BattleFighterData(msg.battlePlayer, 0, false, 0, attackerFactor);
        attackFighters.Add(attackFighter);
        for (int i = 0; i < msg.battleMonsterList.Count; ++i)
        {
            var defendFighter = new BattleFighterData(msg.battleMonsterList[i], 1, true, i, defenderFactor);
            defendFighters.Add(defendFighter);
        }

        maxRound = msg.maxRound > 0 ? msg.maxRound : DEFAULT_MAX_ROUND;

        rushWinKey = msg.winKey;
        rushWinValue = msg.winValue;
    }


    public void Clear()
    {
        fightId = "";
        mapSceneName = "";
        attackFirst = false;
        randomSeed = 0;
        attackFighters.Clear();
        defendFighters.Clear();
        attackerFactor = 1;
        defenderFactor = 1;
        rushWinKey = 0;
        rushWinValue = 0;
        isPlayBack = false;
        operateRecord = null;
    }



    public BattleFighterData GetFighter(int camp, int waveNum)
    {
        if (camp == 0)
        {
            foreach (var fighter in attackFighters)
            {
                if (fighter.waveNum == waveNum)
                    return fighter;
            }
            return null;
        }
        else
        {
            foreach (var fighter in defendFighters)
            {
                if (fighter.waveNum == waveNum)
                    return fighter;
            }
            return null;
        }
    }
}

public class BattleFighterData
{
    public int camp;
    public int waveNum;
    public double angerNum;
    public bool isPlayer;
    public BattlePlayerActorData role;
    public List<BattleActorData> actors;
    public bool isAuto;
    public double damageFactor;

    public BattleFighterData(ProtoBuf.Message.BattlePlayer data, int camp, bool isAuto, int waveNum, double damageFactor)
    {
        this.camp = camp;
        this.waveNum = waveNum;
        this.isAuto = isAuto;
        this.damageFactor = damageFactor;
        this.angerNum = data.inst.anger;
        this.isPlayer = true;
        this.role = new BattlePlayerActorData(data);
        this.actors = new List<BattleActorData>();
        foreach (var actor in data.formation)
        {
            this.actors.Add(new BattleActorData(actor, camp));
        }
    }

    public BattleFighterData(ProtoBuf.Message.BattleMonster data, int camp, bool isAuto, int waveNum, double damageFactor)
    {
        this.camp = camp;
        this.waveNum = waveNum;
        this.isAuto = isAuto;
        this.damageFactor = damageFactor;
        this.angerNum = data.inst.anger;
        this.isPlayer = false;
        this.role = new BattlePlayerActorData(data);
        this.actors = new List<BattleActorData>();
        foreach (var actor in data.formation)
        {
            this.actors.Add(new BattleActorData(actor, camp));
        }
    }

    public BattleFighterData() { }

    public BattleActorData GetBattleActorData(string uid)
    {
        if (this.actors != null)
        {
            foreach (var actor in actors)
            {
                if (actor.uniqueId == uid)
                {
                    return actor;
                }
            }
        }
        return null;
    }
}


public class BattlePlayerActorData
{
    public long playerUID;
    public int serverId;
    public string nickName;
    public int playerLevel;

    public BattlePlayerActorData(ProtoBuf.Message.BattlePlayer data)
    {
        playerUID = data.playerId;
        serverId = data.serverId;
        nickName = data.nickName;
        playerLevel = data.level;
    }

    public BattlePlayerActorData(ProtoBuf.Message.BattleMonster data)
    {
        playerUID = -1;
        serverId = -1;
        nickName = "";
        playerLevel = 0;
    }

    public BattlePlayerActorData()
    {
        playerUID = -1;
        serverId = -1;
        nickName = "";
        playerLevel = 0;
    }
}

public class BattleActorData
{
    public string uniqueId;
    public string heroId;
    public int level;
    public int fpid;
    public int bloodNum;
    public double hp;
    public double maxHp;
    public double att;
    public double pdef;
    public double mdef;
    public double hit;
    public double dodge;
    public double cri;
    public double antiCri;
    public double criFactor;
    public double damageAdd;
    public double damageReduce;
    public string weaponId;
    public int breachedLevel; //突破等级
    public List<BattleActorSkillData> skills;
    public double firstSkillChance;
    public List<BattleActorTalentData> talents;

    public ProtoBuf.Message.BattleHero _battleHero { get; protected set; }
    public BattleActorData(ProtoBuf.Message.BattleHero data, int camp)
    {
        _battleHero = data;
        uniqueId = camp.ToString() + "_" + data.guid;
        heroId = data.id;
        level = data.level;
        fpid = data.pose;
        bloodNum = data.bloodNumber;
        hp = data.inst.curHp;
        maxHp = data.prop.hp;
        att = data.prop.att;
        pdef = data.prop.pdef;
        mdef = data.prop.mdef;
        hit = data.prop.hit;
        dodge = data.prop.dodge;
        cri = data.prop.cri;
        antiCri = data.prop.antiCri;
        criFactor = data.prop.criFactor;
        damageAdd = data.prop.damageAdd;
        damageReduce = data.prop.damageReduce;


        this.weaponId = data.weaponId;
        this.breachedLevel = data.breachedLevel;

        #region UNITY_EDITOR
        //this.weaponId = "";
        #endregion

        this.firstSkillChance = data.SkillCastChance;
        skills = new List<BattleActorSkillData>();
        var arr = data.skillOrder.Split(',');//技能最多三个，但是可能少于三个,例如只有小技能1和大招则传递 0,,2
        if (arr.Length == 3)
        {
            //小技能1
            if (!string.IsNullOrEmpty(arr[0]))
            {
                BattleActorSkillData skill = new BattleActorSkillData(arr[0], 0);
                skills.Add(skill);
            }
            //小技能2
            if (!string.IsNullOrEmpty(arr[1]))
            {
                BattleActorSkillData skill = new BattleActorSkillData(arr[1], 1);
                skills.Add(skill);
            }
            //大招
            if (!string.IsNullOrEmpty(arr[2]))
            {
                BattleActorSkillData skill = new BattleActorSkillData(arr[2], 2);
                skills.Add(skill);
            }
        }

        //解锁的天赋
        talents = new List<BattleActorTalentData>();
        foreach (var tal in data.talentList)
        {
            BattleActorTalentData talent = new BattleActorTalentData(tal);
            talents.Add(talent);
        }
    }
    public BattleActorData(string uniqueId, Dict.DataModel.TableRecruitShowHero data)
    {
        this.uniqueId = uniqueId;
        heroId = data.HeroId;
        level = data.Level;
        fpid = data.Position;
        maxHp = data.Hp;
        hp = maxHp;
        att = data.Attack;
        pdef = data.PhyDefend;
        mdef = data.MagicDefend;
        hit = data.hit;
        dodge = data.dodge;
        cri = data.cri;
        antiCri = data.antiCri;
        criFactor = data.criFactor;
        damageAdd = data.damageAdd;
        damageReduce = data.damageReduce;
        weaponId = "";
        breachedLevel = 1;
        skills = new List<BattleActorSkillData>();
        if (!string.IsNullOrEmpty(data.SkillId1))
        {
            var skill1 = new BattleActorSkillData(data.SkillId1, 0);
            skills.Add(skill1);
        }
        if (!string.IsNullOrEmpty(data.SkillId2))
        {
            var skill2 = new BattleActorSkillData(data.SkillId2, 1);
            skills.Add(skill2);
        }
        if (!string.IsNullOrEmpty(data.UltSkillId))
        {
            var skill3 = new BattleActorSkillData(data.UltSkillId, 2);
            skills.Add(skill3);
        }
        talents = new List<BattleActorTalentData>();
        foreach (var tal in data.Talent_array)
        {
            if (!string.IsNullOrEmpty(tal))
            {
                BattleActorTalentData talent = new BattleActorTalentData(tal);
                talents.Add(talent);
            }
        }
    }

    public BattleActorData(string uniqueId, Dict.DataModel.TableBootHero data)
    {
        this.uniqueId = uniqueId;
        heroId = data.HeroId;
        level = data.Level;
        fpid = data.Position;
        maxHp = data.Hp;
        hp = maxHp;
        att = data.Attack;
        pdef = data.PhyDefend;
        mdef = data.MagicDefend;
        hit = data.hit;
        dodge = data.dodge;
        cri = data.cri;
        antiCri = data.antiCri;
        criFactor = data.criFactor;
        damageAdd = data.damageAdd;
        damageReduce = data.damageReduce;
        weaponId = "";
        breachedLevel = 1;
        skills = new List<BattleActorSkillData>();
        if (!string.IsNullOrEmpty(data.SkillId1))
        {
            var skill1 = new BattleActorSkillData(data.SkillId1, 0);
            skills.Add(skill1);
        }
        if (!string.IsNullOrEmpty(data.SkillId2))
        {
            var skill2 = new BattleActorSkillData(data.SkillId2, 1);
            skills.Add(skill2);
        }
        if (!string.IsNullOrEmpty(data.UltSkillId))
        {
            var skill3 = new BattleActorSkillData(data.UltSkillId, 2);
            skills.Add(skill3);
        }
        talents = new List<BattleActorTalentData>();
        foreach (var tal in data.Talent_array)
        {
            if (!string.IsNullOrEmpty(tal))
            {
                BattleActorTalentData talent = new BattleActorTalentData(tal);
                talents.Add(talent);
            }
        }
    }

}

public class BattleActorSkillData
{
    public string skillId;
    public int skillIndex;
    public BattleActorSkillData(string id, int index)
    {
        skillId = id;
        skillIndex = index;
    }
}

public class BattleActorTalentData
{
    public string talentId;
    public BattleActorTalentData(string id)
    {
        talentId = id;
    }
}




